package com.zmj.sy.mom.srv.aps.utils;

import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeansException;

import java.util.Arrays;

public class MkBeanUtils {

    private MkBeanUtils() {
    }

    @SneakyThrows
    public static <T> T copyProperties(Object source, Class<T> targetClass, String... ignoreProperties) {
        T target = targetClass.getDeclaredConstructor().newInstance();
        org.springframework.beans.BeanUtils.copyProperties(source, target, ignoreProperties);
        return target;
    }


    public static void copyPropertiesIgnore(Object source, Object target, String... ignoreProperties) throws BeansException {
        String[] arr1 = new String[]{"id", "createDateTime", "modifyDateTime", "deleted", "createUsername", "modifyUsername", "factoryId"};

        String[] arr3 = Arrays.copyOf(arr1, arr1.length + ignoreProperties.length);
        System.arraycopy(ignoreProperties, 0, arr3, arr1.length, ignoreProperties.length);

        BeanUtils.copyProperties(source, target,arr3 );
    }
}
